#ifndef SEARCH_H
#define SEARCH_H
#include<string>
#include<iostream>
#include<fstream>
#include<map>
using namespace std;
#include "student.h"
#include "car.h"
#include "xinxi.h"
void Search(){
    map<string,Student> v1;
    string search[11];
    int i=0;
    ifstream fin1("student.txt");
    while(!fin1.eof())
    {
        Student s;
        fin1>>s.name>>s.id;
        v1[s.id]=s;
        //cout<<"学生姓名："<<s.name<<"，学生ID："<<s.id<<endl;
    }
    ifstream fin2("car.txt");
    map<string,Car_id> v21;
    map<string,Dipan> v22;
    map<string,AXG> v23;
    map<string,Camera> v24;
    map<string,Lidar> v25;
    map<string,Gyroscope> v26;
    map<string,Screen> v27;
    map<string,Battery> v28;
    while(!fin2.eof())
    {
        Car_id c;
        Dipan d;
        AXG a;
        Camera ca;
        Lidar l;
        Gyroscope g;
        Screen sc;
        Battery b;
        fin2>>c.car_id>>d.id>>d.xinghao>>d.zhouju>>d.lunju>>d.ldjx>>d.zwbj>>d.qudong>>d.xingcheng>>d.luntai>>d.ltxinghao>>d.ltcc>>a.xinghao>>a.AI>>a.CUDA>>a.Tensor>>a.xiancun>>a.chucun>>ca.xinghao>>ca.sxt>>ca.RGBfbl>>ca.RGB>>ca.FOV>>ca.sdzl>>l.xinghao>>l.tds>>l.csfw>>l.gonghao>>g.xinghao>>g.changjia>>sc.xinghao>>sc.chicun>>b.canshu>>b.gongdian>>b.cdsc;
        v21[c.car_id]=c;
        v22[c.car_id]=d;
        v23[c.car_id]=a;
        v24[c.car_id]=ca;
        v25[c.car_id]=l;
        v26[c.car_id]=g;
        v27[c.car_id]=sc;
        v28[c.car_id]=b;
        search[i]=c.car_id;
        i++;
        //cout<<c.car_id<<' '<<d.id<<endl;
    }
    // for(int j=0;j<i;j++)
    // {
    //     cout<<search[j];
    // }
    map<string,Xinxi> v3,v4;
    ifstream fin3("xinxi.txt");
    while(!fin3.eof())
    {
        Xinxi x;
        fin3>>x.id>>x.car_id;
        v3[x.id]=x;
        v4[x.car_id]=x;
        //cout<<x.id<<' '<<x.car_id<<endl;
    }

    while(true)
    {
        cout<<"请输入要查找的信息"<<endl;
        cout<<"查找学生信息请输入1"<<endl;
        cout<<"查找小车信息请输入2"<<endl;
        cout<<"查找学生使用小车信息请输入3"<<endl;
        cout<<"退出请输入4"<<endl;
        int chazhao;
        cin>>chazhao;
        if(chazhao==1)
        {
            while(true)
            {
                cout<<"请输入要查询的学生ID,退出请输入q"<<endl;
                string id;
                cin>>id;
                if(id=="q")
                {
                    break;
                }
                Student s1=v1[id];
                cout<<"学生姓名："<<s1.name<<"，学生ID："<<s1.id<<endl;
            }
        }
        else if(chazhao==2)
        {
            while(true)
            {
                cout<<"请输入要查找的小车编号：";
                string car_id;
                cin>>car_id;
                Car_id c1=v21[car_id];
                Dipan d1=v22[car_id];
                AXG a1=v23[car_id];
                Camera ca1=v24[car_id];
                Lidar l1=v25[car_id];
                Gyroscope g1=v26[car_id];
                Screen sc1=v27[car_id];
                Battery b1=v28[car_id];
                c1.get();
                d1.get();
                a1.get();
                ca1.get();
                l1.get();
                g1.get();
                sc1.get();
                b1.get();
                cout<<"如果要查看所有小车信息，请输入1。不查看退出请输入2"<<endl;
                int search1;
                cin>>search1;
                if(search1==1)
                {
                    int search2=0;
                    while(true)
                    {   
                        cout<<"输入n显示下一辆小车信息，输入p显示上一辆小车信息，退出请输入q"<<endl;
                        string a;
                        a=search[search2];
                        Car_id c2=v21[a];
                        Dipan d2=v22[a];
                        cout<<"小车编号："<<c2.car_id<<"小车底盘编号："<<d2.id<<endl;
                        string b;
                        cin>>b;
                        if(b=="n"&&search2<9)
                        {
                            search2++;
                            string a;
                            a=search[search2];
                            Car_id c3=v21[a];
                            Dipan d3=v22[a];
                            cout<<"小车编号："<<c3.car_id<<"小车底盘编号："<<d3.id<<endl;//其他信息就先不显示了太多了而且重复
                        }
                        if(b=="p"&&search2>0)
                        {
                            search2--;
                            string a;
                            a=search[search2];
                            Car_id c4=v21[a];
                            Dipan d4=v22[a];
                            cout<<"小车编号："<<c4.car_id<<"小车底盘编号："<<d4.id<<endl;//其他信息就先不显示了太多了而且重复
                        }
                        if(b=="n"&&search2==9)
                        {
                        cout<<"已到最后一辆小车"<<endl;
                        }
                        if(b=="p"&&search2==0)
                        {
                            cout<<"已到第一辆小车"<<endl;
                        }
                        if(b=="q")
                        {
                            break;
                        }
                        
                    }
                }
                else if(search1==2)
                {
                    break;
                }
                else
                {
                    cout<<"输入错误，请重新输入。"<<endl;
                }
            }
        }
        else if(chazhao==3)
        {
        while(true)
        {
                cout<<"查找学生使用的小车请输入1，查找使用小车的学生请输入2，退出请输入3"<<endl;
                int l;
                cin>>l;
                if(l==1)
                {
                    cout<<"请输入学生学号:"<<endl;
                    string id1;
                    cin>>id1;
                    Xinxi x1=v3[id1];
                    cout<<"使用学生学号："<<x1.id<<' '<<"使用的小车编号"<<x1.car_id<<endl;
                }
                else if(l==2)
                {
                    cout<<"请输入小车编号:"<<endl;
                    string id2;
                    cin>>id2;
                    Xinxi x2=v4[id2];
                    cout<<"使用学生学号："<<x2.id<<' '<<"使用的小车编号"<<x2.car_id<<endl;
                }
                else if(l==3)
                {
                    break;     
                }
                else{
                    cout<<"输入错误，请重新输入。"<<endl;
                }
            }
        }
        else if(chazhao==4)
        {
            break;
        }
        else
        {
        cout<<"输入错误请重新输入"<<endl;
        }
    }
    
    fin1.close();
    fin2.close();
    fin3.close();
}

#endif